<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.yc.comm.Constant"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String strUserRoleName = (String)session.getAttribute(Constant.USER_ROLE);
String strUserName = (String)session.getAttribute(Constant.USER_NAME);
//System.out.println("strUserRoleName = "+strUserRoleName);
%>


<html>
  <head>
    <base href="<%=basePath%>">    
    <link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/ext-all.css">  
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/edit-grid.css">  
	<script type="text/javascript" src="<%=path%>/js/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/DWRTreeLoader.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/query-dwr-proxy.js"></script>	
	<script type="text/javascript" src="<%=path%>/js/ext/SearchField.js"></script>
	<script type='text/javascript' src='/btsm/dwr/interface/JFiberWeb.js'></script>
	<script type='text/javascript' src='/btsm/dwr/engine.js'></script>
	<script type='text/javascript' src='/btsm/dwr/util.js'></script>	 		
  </head>
<body> 
<form id="showSectionForm" action="<%=path%>/pages/browse/fiber/SectionOutInfo.jsp" method="POST">
	<input type="hidden" name="id" id="strSectionID">
	<input type="hidden" name="name" id="strSectionName">
</form>
<div id="tabDiv" style="height:100%;width:100%">
	<div id="westDiv"/>	
	<div id="contentsDiv" style="height:100%"/>
</div>

<div id="sectionListWin">
    <div id="otherSectionList"/>
</div>

<form id="showMapForm" action="<%=path%>/pages/fiber/FiberLinkMapDispatch.jsp">
	<input type="hidden" name="linkId" id="strLinkID">
</form>

<script type="text/javascript">
var	ds;
var simpleForm ;
Ext.form.Field.prototype.msgTarget = 'side'; 

Ext.onReady(function()
{
	var viewport = new Ext.Viewport({
	    layout:'border',
	    frame:true,
	    items:[ 
	    	{
		        region: 'east',
		        contentEl: 'westDiv',
		        margins:'110 5 30 0',
		        split: true,
		        border: false,
		        collapsible: true,
		        width: 300
		    },
	    	{
		        region: 'center',
		        contentEl: 'contentsDiv',
		        margins:'110 0 30 5',
		        split: true,
		        border: false	
		    }]
		});
   	 
	var sm = new Ext.grid.CheckboxSelectionModel({singleSelect: true});	
	var recordType = Ext.data.Record.create([								
                			   {name: 'id', type: "string"},
							   {name: 'linkID', type: "string"},
							   {name: 'ocID', type: "string"},
                	           {name: 'ocName', type: "string"},
                	           {name: 'ocBeginName', type: "string"},
							   {name: 'ocBeginLng', type: "string"},
							   {name: 'ocBeginLat', type: "string"},
                	           {name: 'ocEndName', type: "string"},
							   {name: 'ocEndLng', type: "string"},
							   {name: 'ocEndLat', type: "string"},
							   {name: 'ocType', type: "string"},
							   {name: 'ocNum', type: "string"},
                	           {name: 'ocLength', type: "string"},
                	           {name: 'ocInspectorName', type: "string"},
							   {name: 'notes', type: "string"},
							   {name: 'canEdit', type: "string"},
                	           {name: 'ocInspectorPhone', type: "string"}
                	     ]);

	var cm  = new Ext.grid.ColumnModel(
			[
				sm,	            
	            {header: "中继段名称",  sortable: true, dataIndex: 'ocName',align:'left'},
	            {header: "起点名称",  sortable: true, dataIndex: 'ocBeginName',align:'left'},
	            {header: "终点名称",  sortable: true, dataIndex: 'ocEndName',align:'left'},
	            {header: "中继段长度",  sortable: true, dataIndex: 'ocLength',align:'left'}, 
				{header: "canEdit",  sortable: true, dataIndex: 'canEdit',align:'left'},
				//{header: "地图", sortable: false, dataIndex: 'id',renderer: showMap},
				//{header: "详细信息", sortable: false, dataIndex: 'id',renderer: showInfo},
				{header: "详细", sortable: false, dataIndex: 'id',renderer: showInfoOther} 			
			]
		);
	function showMap(id)	
	{
		return "<input type='button' value='地图' class='x-btn button' onclick='doFiberMap(\"" + id  +   "\")'>";  
	}	
	function showInfo(value, cellmeta, record, rowIndex, columnIndex, store)
	{
		var name = record.get("ocName");
		var canEdit = record.get("canEdit");
		if(canEdit === '<%=Constant.EDIT_YES%>' )
			return "<input type='button' value='详细信息' class='x-btn button' onclick='doShowSection(\"" + value  +   "\",\""+name+"\")'>";  
		else
			return "---";
	}
	
	function showInfoOther(value, cellmeta, record, rowIndex, columnIndex, store)
	{
		var name = record.get("ocName");
		var canEdit = record.get("canEdit");
		//if(canEdit === '<%=Constant.EDIT_YES%>' )
			return "<input type='button' value='详细' class='x-btn button' onclick='doShowSectionInfo(\"" + value  +   "\",\""+name+"\")'>";  
		//else
			//return "---";
	}
	
	function showDelete(value, cellmeta, record, rowIndex, columnIndex, store)
	{
		var id = record.get("id");
		var canEdit = record.get("canEdit");
		if(canEdit === '<%=Constant.EDIT_YES%>' )
			return "<input type='button' value='删除' class='x-btn button' onclick='doDeleteSectionFromLink(\"" + id  +   "\")'>";  
		else
			return "---";
	}

	ds = new Ext.data.Store({
        proxy: new Ext.data.DWRProxy(JFiberWeb.getSectionInfoListForBrowse, true),	
        reader: new Ext.data.ListRangeReader({
            totalProperty: 'totalSize',
            id: 'id'
        }, recordType),
        sortInfo:{field:'id', direction:'ASC'}// 排序信息
    });


	var contentDiv = Ext.get("contentsDiv");
	var sectionGrid = new Ext.grid.GridPanel({
	    	el: 'contentsDiv',	    	
	        ds: ds,
	        cm: cm,
			sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true,
                    listeners: {
                        rowselect: function(sm, row, rec) { 
                            simpleForm.getForm().loadRecord(rec);
							//var canEdit = rec.get("canEdit");
							//if(canEdit === '<%=Constant.EDIT_YES%>' ){ 
								//simpleForm.form.items.each(function(item){
									//item.enable();
								//});
								//simpleForm.buttons[0].enable();  
								//simpleForm.buttons[1].enable();
							//} else{
								//simpleForm.form.items.each(function(item){
									//item.disable();
								//});
								//simpleForm.buttons[0].disable();  
								//simpleForm.buttons[1].disable();								
							//}
                        }
                    }
                }),
			title: '中继段信息列表', 
			width: contentDiv.getComputedWidth(),
			height: contentDiv.getComputedHeight(), 
	        frame:true,
	        collapsible:false,
			autoShow :true, 
			autoExpandColumn:1, 
	        enableDragDrop:false, 
	        tbar: [
					'查询: ', ' ',
					new Ext.ux.form.SearchField({
						store:ds,
						width:320
					}) 
				],		
			bbar: new Ext.PagingToolbar({
			        pageSize: 17,
			        store: ds,
			        displayInfo: true,
			        displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
			        emptyMsg: "没有记录"
			    })
					
					
				
	    });
    
	sectionGrid.render(); 
	ds.on('beforeload', function() {
		  ds.baseParams = {
				'<%=Constant.USER_ROLE%>':'<%=strUserRoleName%>',
				'<%=Constant.USER_ID%>':'<%=strUserName%>',
				start:0,
				limit:17
		  };
		});		
	
	ds.load({params:{start:0,limit:17}});	
    cm.setHidden(5,true);

	ds.on('load', function() {
		   sectionGrid.getSelectionModel().selectFirstRow(); 
		});		
	
	function fiberUsedInfo()
	{
		var record = sectionGrid.getSelectionModel().getSelected();// 返回值为 Record 类型
		if(!record)
		{
			Ext.Msg.alert("提示","请先选择中继段!");
			return;
		}
		document.getElementById("strSectionID").value = record.get("ocID"); 
		document.getElementById("strSectionName").value = record.get("ocName"); 
		document.getElementById("showSectionForm").action = "<%=path%>/pages/fiber/FiberList.jsp";
		document.getElementById("showSectionForm").submit();  
		     
	}
	
	
	simpleForm = new Ext.FormPanel({
        labelWidth: 75,
        frame:true,
        title: '总体信息', 
        width: 300,
		height:410,
        defaults: {width: 180},
        defaultType: 'textfield',
        items: [
				{
					xtype : 'hidden',
					name: 'linkID'
				},
				{
					xtype : 'hidden',
					name: 'ocID'
				},{
					fieldLabel: '中继段名称',
					name: 'ocName',
					allowBlank:false,
					disabled:true,
					blankText :'请输入中继段名称'	
				},{
					fieldLabel: '起点名称',
					name: 'ocBeginName',
					allowBlank:false,
					disabled:true,
					blankText :'请输入起点名称'	
				},{
					xtype:'numberfield',
					fieldLabel: '起点经度',
					allowDecimals: true, 
					decimalPrecision:5,
					name: 'ocBeginLng',
					allowBlank:false,
					disabled:true,
					blankText :'请输入起点经度'	
				},
				{
					xtype:'numberfield',
					fieldLabel: '起点维度',
					allowDecimals: true, 
					decimalPrecision:5,
					name: 'ocBeginLat',
					allowBlank:false,
					disabled:true,
					blankText :'请输入起点维度'	
				},{
					fieldLabel: '终点名称',
					name: 'ocEndName',
					allowBlank:false,
					disabled:true,
					blankText :'请输入终点名称'	
				},{
					xtype:'numberfield',
					fieldLabel: '终点经度',
					allowDecimals: true, 
					decimalPrecision:5,
					name: 'ocEndLng',
					allowBlank:false,
					disabled:true,
					blankText :'请输入终点经度'	
				},{
					xtype:'numberfield',
					fieldLabel: '终点维度',
					allowDecimals: true, 
					decimalPrecision:5,
					name: 'ocEndLat',
					allowBlank:false,
					disabled:true,
					blankText :'请输入终点维度'	
				},{
					fieldLabel: '光缆型号',
					name: 'ocType',
					allowBlank:false,
					disabled:true,
					blankText :'请输入光缆型号'	
				},{
					xtype:'numberfield',
					fieldLabel: '光缆芯数',
					name: 'ocNum',
					allowBlank:false,
					disabled:true,
					blankText :'请输入光缆芯数'	
				},{
					xtype:'numberfield',
					fieldLabel: '中继段长度',
					allowDecimals: true, 
					name: 'ocLength',
					allowBlank:false,
					disabled:true,
					blankText :'请输入中继段长度'	
				},{
					fieldLabel: '巡检员姓名',
					name: 'ocInspectorName',
					allowBlank:false,
					disabled:true,
					blankText :'请输入巡检员姓名'	
				},{
					fieldLabel: '联系电话',
					name: 'ocInspectorPhone',
					allowBlank:false,
					disabled:true,
					blankText :'请输入联系电话'	
				},{
					fieldLabel: '敷设方式',
					disabled:true,
					name: 'notes'
				}
        ] 
    });

    simpleForm.render("westDiv");
	
	function saveSectionInfo()
	{
		if (!simpleForm.getForm().isValid())
			return;
		var form = simpleForm.getForm().getValues(false);
		SectionInfoBo = {};
		SectionInfoBo.ocID = form.ocID;
		SectionInfoBo.ocName = form.ocName;
		SectionInfoBo.ocBeginName = form.ocBeginName;
		SectionInfoBo.ocBeginLng = form.ocBeginLng;
		SectionInfoBo.ocBeginLat = form.ocBeginLat;
		SectionInfoBo.ocEndName = form.ocEndName;
		SectionInfoBo.ocEndLng = form.ocEndLng;
		SectionInfoBo.ocEndLat = form.ocEndLat;
		SectionInfoBo.ocType = form.ocType;
		SectionInfoBo.ocNum = form.ocNum;
		SectionInfoBo.ocLength = form.ocLength;
		SectionInfoBo.ocInspectorName = form.ocInspectorName;
		SectionInfoBo.ocInspectorPhone = form.ocInspectorPhone;
		SectionInfoBo.notes = form.notes;
		SectionInfoBo.linkID = form.linkID;;	
		SectionInfoBo.userId = '<%=strUserName%>';		
		JFiberWeb.createSectionInfo(SectionInfoBo,SectionInfoBo.ocName,function(data)
		{
			if(data)
			{ 
				Ext.Msg.alert('成功',"操作成功！"); 
				ds.load({params:{start:0,limit:17}});
				simpleForm.getForm().reset();
			}else
			{
				Ext.Msg.alert("失败","操作失败!");
			}	
		})
		 
	}
	
	var parentPanel = new Ext.FormPanel({
        labelWidth: 75,
        frame:true,
        //title: '总体信息', 
        width: 300,
		height:600,
        defaults: {width: 180},
        defaultType: 'textfield',
        items: simpleForm
		});
	parentPanel.render("westDiv");		
	
	
	
	
		
})


function doDeleteSectionFromLink(id)
{
	JFiberWeb.isUsedByLink(id,function(data){
	if(data)
	{
		Ext.MessageBox.show({
		    title:"提示",
		    msg:"该中继段已经被添加到光纤环，请从环中删除该中继段后再删除!", 
		    icon:Ext.MessageBox.WARNING
		});			
		return;
	}else
	{
		Ext.MessageBox.confirm('确认删除', '确认删除该中继段?', 
				function(btn) {
				 if(btn == 'yes') // 选中了是按钮	
				 {	    	     	
					 JFiberWeb.deleteSectionInfo(id, function(data) {
					 if(data) {							    	     		
						 ds.load({params:{start:0,limit:17}}); 
					 }else 
					 {
						Ext.Msg.alert("删除失败","数据删除失败!");
					 }
					 });
					
				 }
				}
			);
	}	
	})	
	
}


function doShowSection(id,name)
{
	document.getElementById("strSectionID").value = id; 
	document.getElementById("strSectionName").value = name; 
	document.getElementById("showSectionForm").action = "<%=path%>/pages/fiber/SectionOutInfo.jsp";
	document.getElementById("showSectionForm").submit();
}

function doShowSectionInfo(id,name)
{
	document.getElementById("strSectionID").value = id; 
	document.getElementById("strSectionName").value = name; 
	document.getElementById("showSectionForm").action = "<%=path%>/pages/browse/fiber/SectionDetailInfo.jsp";
	document.getElementById("showSectionForm").submit();
}

function doFiberMap(id)
{
	document.getElementById("strLinkID").value = id;
	document.getElementById("showMapForm").submit();
}

</script>

</body>